﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Emoney.UserTraining.Model;
using System.Data.SqlClient;
using System.Data;
using Emoney.UserTraining.DAL;

namespace Emoney.UserTraining.DAL
{
    public class TrainDAL
    {
        string con = DBConn.emweb_new;

        //
        //TODO: 在此处添加构造函数逻辑
        //
        /// <summary>
        /// 获取培训标签 
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public DataSet GetTrainTarget(Web_Train t)
        {
            SqlDataReader reader = null;
            try
            {
                SQLTools tool = new SQLTools();
                tool.AddSqlParameter("@sign", SqlDbType.Int, t.sign);
                tool.AddSqlParameter("@id", SqlDbType.Int, t.id);
                tool.AddSqlParameter("@area", SqlDbType.VarChar, t.area);
                tool.AddSqlParameter("@placenum", SqlDbType.VarChar, t.placenum);
                //throw new Exception(con);
                DataSet ds = SqlHelper.ExecuteGetDataSet(con, CommandType.StoredProcedure, "web_TrainPlace_Select", tool.GetSqlParameters());
                return ds;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
               }
            }
        }
        
        /// <summary>
        /// 预约信息录入
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public string InsertPlaceUser(Web_Train t)
        {
            SqlDataReader reader = null;
            try
            {
                SQLTools tool = new SQLTools();
                tool.AddSqlParameter("@sign", SqlDbType.Int, t.sign);
                tool.AddSqlParameter("@id", SqlDbType.Int, t.id);
                tool.AddSqlParameter("@username", SqlDbType.VarChar, t.username);
                tool.AddSqlParameter("@area", SqlDbType.VarChar, t.area);
                tool.AddSqlParameter("@reservenum", SqlDbType.VarChar, t.reservenum);
                tool.AddSqlParameter("@placenum", SqlDbType.VarChar, t.placenum);
                tool.AddSqlParameter("@isattend", SqlDbType.Int, t.isattend);
                DataSet ds = SqlHelper.ExecuteGetDataSet(con, CommandType.StoredProcedure, "web_TrainUser_InsAndSelect", tool.GetSqlParameters());
                return ds.Tables[0].Rows[0][0].ToString();
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
    }
}
